cmake_minimum_required(VERSION 3.16)
include(CMakePrintHelpers)
project(obs_plugin_obj)
file(GLOB_RECURSE native_dtfuzz_srcs src/dt_fuzz/*.cpp)
MESSAGE("Compling the llt of file plugin.")
option(DTFUZZ "Compile in DTFUZZ mode" OFF)
add_definitions(-w)
add_definitions(-DBOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC)
add_definitions(-D_OBS)
SET(LLT ON)

add_definitions(-DBOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC)

# 定义一些公共变量
SET(PLUGIN_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
SET(PLUGIN_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../src)
SET(PLUGIN_FRAMEWORK_PATH ${PLUGIN_ROOT_PATH}/framework)
SET(SCANNER_ROOT_PATH ${PLUGIN_ROOT_PATH}/FS_Scanner)
SET(BACKUP_ROOT_PATH ${PLUGIN_ROOT_PATH}/FS_Backup)
SET(FRAMEWORK_INC_PATH ${PLUGIN_ROOT_PATH}/framework/inc)
SET(PLUGIN_COMMON_PATH ${PLUGIN_SRC_PATH}/common)
SET(PLUGIN_FRAMEWORK_LIB_PATH ${PLUGIN_FRAMEWORK_PATH}/lib)
SET(MODULE_ROOT_PATH ${PLUGIN_ROOT_PATH}/Module)
SET(OPEN_SRC_PATH ${MODULE_ROOT_PATH}/third_open_src)
SET(PLATFORM_PATH ${MODULE_ROOT_PATH}/platform)
SET(OPENSRC_THRIFT_INC_PATH ${OPEN_SRC_PATH}/thrift_rel/include/)
set(AGENT_SDK_PATH ${PLUGIN_FRAMEWORK_PATH}/dep/agent_sdk)
SET(DT_UTILS_PATH ${MODULE_ROOT_PATH}/dt_utils)
SET(GOOGLE_TEST_PATH ${DT_UTILS_PATH}/gmock/googletest-release)
SET(MOCKCPP_PATH ${DT_UTILS_PATH}/mockcpp/build/mockcpp)
SET(PLUGIN_SCANNER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../FS_Scanner)
SET(PLUGIN_BACKUP_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../FS_Backup)

# 查看目标库是否存在
if(TARGET curl_http_util)
    MESSAGE(STATUS "curl_http_util existed")
else()
    add_subdirectory(${MODULE_ROOT_PATH}/src/curl_http curl_http)
endif()

if (DEFINED DTFUZZ)
        message(STATUS "DTFUZZ defined: " ${DTFUZZ})
else ()
        message(STATUS "DTFUZZ un-defined: " ${DTFUZZ})
endif()
if(DTFUZZ)
SET(SECODE_FUZZ_INCLUDE_PATH ${DT_UTILS_PATH}/secodefuzz_rel/include)
SET(SECODE_FUZZ_LIB_PATH ${DT_UTILS_PATH}/secodefuzz_rel/lib)
SET(SECODE_FUZZ_LIB_NAME Secodefuzz)
set(obs_test_src
    src/ObsTest.cpp
    ${native_dtfuzz_srcs}
)
add_executable(test_obs_plugin
    ${obs_test_src}
)
set(FUZZ_OPT "-fdump-rtl-expand -fsanitize-coverage=trace-pc")
add_definitions(-DFUZZ_ENABLED)
else()

aux_source_directory(src obsTest)
aux_source_directory(src/job jobTest)
aux_source_directory(src/obs_service/obs_resource obs_AppServiceTest)
aux_source_directory(src/obs_service/obs_common obs_common)
aux_source_directory(src/obs_service/obs_index obs_ObjectStorageIndexJobTest)
aux_source_directory(src/obs_service/obs_backup obs_BackupTest)
aux_source_directory(src/utils obs_utils)
aux_source_directory(src/obs_service/obs_restore obs_RestoreTest)

add_executable(test_obs_plugin
    ${obsTest}
    ${jobTest}
    ${obs_AppServiceTest}
    ${obs_common}
    ${obs_BackupTest}
    ${obs_utils}
    ${obs_RestoreTest}
    ${obs_ObjectStorageIndexJobTest}
)
endif()

add_subdirectory(../src nas_src)

set(OBS_PLUGIN_INC_FOLDER
    ${MODULE_ROOT_PATH}/dt_utils/llt_stub

    # 业务代码依赖
    ${PLUGIN_ROOT_PATH}
    ${PLUGIN_SRC_PATH}
    ${PLUGIN_SRC_PATH}/common
    ${PLUGIN_SRC_PATH}/common/application
    ${PLUGIN_SRC_PATH}/common/constant
    ${PLUGIN_SRC_PATH}/job
    ${PLUGIN_SRC_PATH}/obs_service/
    ${PLUGIN_SRC_PATH}/obs_service/obs_restore
    ${PLUGIN_SRC_PATH}/obs_service/obs_resource
    ${PLUGIN_SRC_PATH}/obs_service/obs_backup
    ${PLUGIN_SRC_PATH}/obs_service/obs_common
    ${PLUGIN_SRC_PATH}/obs_service/obs_index
    ${PLUGIN_SRC_PATH}/utils

    # 开源依赖
    ${PLATFORM_PATH}/SecureCLib_rel/include
    ${PLATFORM_PATH}/KMCv3_infra_rel/include
    ${PLATFORM_PATH}/KMCV3_rel/include
    ${PLATFORM_PATH}/ALiCloudSDK_rel/include
    ${OPEN_SRC_PATH}/boost_rel/include
    ${OPEN_SRC_PATH}/openssl_rel/include
    ${OPEN_SRC_PATH}/libxml2_rel/include
    ${OPEN_SRC_PATH}/jsoncpp_rel/include
    ${OPEN_SRC_PATH}/esdk_rel/include

    # framework依赖
    ${PLUGIN_FRAMEWORK_PATH}/dep/agent_sdk/include
    ${FRAMEWORK_INC_PATH}
    ${FRAMEWORK_INC_PATH}/job
    ${FRAMEWORK_INC_PATH}/job_mgr
    ${FRAMEWORK_INC_PATH}/client
    ${FRAMEWORK_INC_PATH}/common
    ${FRAMEWORK_INC_PATH}/thrift_interface
    ${FRAMEWORK_INC_PATH}/rpc
    ${FRAMEWORK_INC_PATH}/rpc/certificateservice
    ${OPENSRC_THRIFT_INC_PATH}

    # Module依赖
    ${MODULE_ROOT_PATH}
    ${MODULE_ROOT_PATH}/src
    ${MODULE_ROOT_PATH}/src/parser
    ${MODULE_ROOT_PATH}/src/common
    ${MODULE_ROOT_PATH}/src/libobs_ctx
    ${MODULE_ROOT_PATH}/src/threadpool
    ${MODULE_ROOT_PATH}/third_open_src/boost_rel/lib

    ${PLUGIN_SCANNER_PATH}/localhost_src
    ${PLUGIN_SCANNER_PATH}/localhost_src/common
    ${PLUGIN_SCANNER_PATH}/localhost_src/checkpoint
    ${PLUGIN_SCANNER_PATH}/localhost_src/filter
    ${PLUGIN_SCANNER_PATH}/localhost_src/interface
    ${PLUGIN_SCANNER_PATH}/localhost_src/model
    ${PLUGIN_SCANNER_PATH}/localhost_src/service
    ${PLUGIN_SCANNER_PATH}/localhost_src/statistics
    ${PLUGIN_SCANNER_PATH}/localhost_src/utils
    ${PLUGIN_BACKUP_PATH}/src/model
    ${PLUGIN_BACKUP_PATH}/src/service
    ${PLUGIN_BACKUP_PATH}/src/common
    ${PLUGIN_BACKUP_PATH}/src/common/backup_layout/

     # Backup依赖
     ${BACKUP_ROOT_PATH}/src/model
     ${BACKUP_ROOT_PATH}/src/service
     ${BACKUP_ROOT_PATH}/src/common

    # gtest
    ${GOOGLE_TEST_PATH}/googletest/include
    ${GOOGLE_TEST_PATH}/googlemock/include
    ${SECODE_FUZZ_INCLUDE_PATH}

    # mockcpp
    ${MOCKCPP_PATH}/include
)

target_include_directories(test_obs_plugin
    PRIVATE
    ${OBS_PLUGIN_INC_FOLDER}
)

set(OBS_PLUGIN_LIB_FOLDER
    ${PLATFORM_PATH}/SecureCLib_rel/lib
    ${PLATFORM_PATH}/KMCv3_infra_rel/lib
    ${PLATFORM_PATH}/KMCV3_rel/lib
    ${PLATFORM_PATH}/ALiCloudSDK_rel/lib
    ${OPEN_SRC_PATH}/jsoncpp_rel/libs
    ${OPEN_SRC_PATH}/boost_rel/lib
    ${OPEN_SRC_PATH}/esdk_rel/lib
    ${OPEN_SRC_PATH}/curl_rel/lib
    ${OPEN_SRC_PATH}/leveldb_rel/out-shared
    ${OPEN_SRC_PATH}/protobuf_rel/lib
    ${OPEN_SRC_PATH}/sqlite_rel/unixODBC/lib
    ${OPEN_SRC_PATH}/LibRdKafka_rel/libs
    ${OPEN_SRC_PATH}/libssh2_rel/lib
    ${OPEN_SRC_PATH}/openssl_rel/lib
    ${OPEN_SRC_PATH}/soci_rel/lib64
    ${OPEN_SRC_PATH}/libiconv_rel/lib
    ${OPEN_SRC_PATH}/openssl_rel/lib
    ${OPEN_SRC_PATH}/libevent_rel/lib
    ${PLUGIN_FRAMEWORK_PATH}/lib
    ${PLUGIN_FRAMEWORK_PATH}/lib/dme
    ${PLUGIN_FRAMEWORK_PATH}/lib/3rd
    ${PLUGIN_FRAMEWORK_PATH}/lib/agent_sdk
    ${PLUGIN_FRAMEWORK_PATH}/lib/dme/3rd
    ${DME_OPENSRC_CARES_LIB_PATH}
    ${SECODE_FUZZ_LIB_PATH}
)

target_link_directories(test_obs_plugin
    PRIVATE
    ${OBS_PLUGIN_LIB_FOLDER}
    ${AGENT_SDK_PATH}/lib
    ${CMAKE_CURRENT_SOURCE_DIR}/../build-cmake
    ${CMAKE_CURRENT_SOURCE_DIR}/../build-cmake/system
    ${CMAKE_CURRENT_SOURCE_DIR}/../build-cmake/device_access
    ${GOOGLE_TEST_PATH}/lib
    ${MODULE_ROOT_PATH}/lib
    ${PLUGIN_SCANNER_PATH}/build-cmake-file
    ${PLUGIN_BACKUP_PATH}/build-cmake
    # mockcpp
    ${MOCKCPP_PATH}/lib
)

set(KMC_OPT "-DWSEC_COMPILE_CAC_OPENSSL -DWSEC_USE_OPENSSL_110 -DWSEC_LINUX -DKMC_MULTIPROCESS -DWSEC_ERR_CODE_BASE=0x10000000")

target_compile_options(test_obs_plugin
    PRIVATE
    -std=c++1z -fno-access-control -DBOOST_LOG_DYN_LINK
    -g -pipe -fPIC -DLINUX ${KMC_OPT}
    -fprofile-arcs -ftest-coverage
    -Wl,-Bstatic -Wl,-Bdynamic
)

target_link_libraries(test_obs_plugin
    basic_job
    curl_http_util
    pthread
    obs_plugin
    pluginsdk
    securec
    json
    boost_chrono
    boost_atomic
    boost_thread
    boost_filesystem
    boost_system
    boost_regex
    boost_log
    boost_date_time
    eSDKOBS
    eSDKLogAPI
    alibabacloud-oss-cpp-sdk
    iconv
    ssl
    crypto
    thrift_interface
    thrift_client
    rpc
    common_util
    config_reader_util
    log_util
    system
    device_access
    Scanner
    Backup
    kmcv3
    KMC
    SDP
    gmock gtest gtest_main gmock_main gcov
    mockcpp
    ${SECODE_FUZZ_LIB_NAME}
    # Module依赖
    obs_ctx
    parser
    threadpool
    system
    Scanner
    Backup
)
